package com.zy.dp.mediator.example2;

/**
 * �����࣬ʵ���н��߽ӿ�
 */
public class MotherBoard implements Mediator
{

	private CDDriver cdDriver = null;

	private CPU cpu = null;

	private VideoCard videoCard = null;

	private SoundCard soundCard = null;

	public void setCdDriver(CDDriver cdDriver)
	{
		this.cdDriver = cdDriver;
	}

	public void setCpu(CPU cpu)
	{
		this.cpu = cpu;
	}

	public void setVideoCard(VideoCard videoCard)
	{
		this.videoCard = videoCard;
	}

	public void setSoundCard(SoundCard soundCard)
	{
		this.soundCard = soundCard;
	}

	public void changed(Colleague colleague)
	{
		if (colleague == cdDriver)
		{

			this.opeCDDriverReadData((CDDriver) colleague);
		}
		else if (colleague == cpu)
		{

			this.opeCPU((CPU) colleague);
		}
	}

	private void opeCDDriverReadData(CDDriver cd)
	{

		String data = cd.getData();

		this.cpu.executeData(data);
	}

	private void opeCPU(CPU cpu)
	{

		String videoData = cpu.getVideoData();
		String soundData = cpu.getSoundData();

		this.videoCard.showData(videoData);
		this.soundCard.soundData(soundData);
	}

}
